// -----------------------------------------------初始化----------------------------------------------

const express = require('express');
const app = express();

// 前端的html css js 必须 托管静态资源
app.use('/node_modules',express.static('./node_modules'));

// 配置ejs
app.set('view engine','ejs');
app.set('views','./views');

// 获取请求的参数 body-parser
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended:false}));

const fs = require('fs');
const path = require('path');

// 配置session
const session = require('express-session');
app.use(
    session({
        secret:'加密',
        resave:false,
        saveUninitialized:false
    })
)

// app.js-----router-----controller-----db

// -----------------------------------------------路由导入----------------------------------------------

// // 首页模块
// const router1 = require('./router/index.js');
// app.use(router1);

// // 用户登录注册模块
// const router2 = require('./router/user.js');
// app.use(router2);

// 循环导入router
fs.readdir(path.join(__dirname,'./router'),(err,filenames) => {
    if(err) return console.log('读取失败');
    // console.log(filenames);
    filenames.forEach(items => {
        // console.log(items);
        let router = require(path.join(__dirname,'./router',items));
        app.use(router);
    })
})



// -----------------------------------------------开启服务器----------------------------------------------

app.listen(80,() => {
    console.log('success at 80');
});
